//
//  AEPointsAcquireTopView.m
//  AESOLAR_IOS
//
//  Created by Bin Tang on 2024/10/16.
//  Copyright © 2024 Mr.Wang. All rights reserved.
//

#import "AEPointsAcquireTopView.h"
#import "AE_Solar-Swift.h"
#import "AEPointsAcquireDailyView.h"
#import "AEPointsAcquireViewModel.h"


@interface AEPointsAcquireTopView ()

@property (nonatomic, strong) AEPointsAcquireViewModel *viewModel;

@property (nonatomic, strong) UIImageView *topImgView;

@property (nonatomic, strong) AEPointsAcquireDailyView *dailyView;

/// 点击签到
@property (nonatomic, strong) UIButton *btnSignIn;

@end

@implementation AEPointsAcquireTopView

- (void)initWithSubView {
    [super initWithSubView];
    
    self.backgroundColor = [UIColor colorWithHexString:@"#F6F8F8"];
    
    [self initWithTopImgView];
    
}

- (void)initWithTopImgView {
    if (!_topImgView) {
        CGRect frame = CGRectMake(0, 0, self.width, 260);
        if (IPHONEX_TOP_SPACE == 0) {
            frame.size.height = frame.size.height - 24 - 4;
        }
        UIImage *image = [UIImage imageNamed:@"ic_points_acquire_top_bg"];
        _topImgView = [UIImageView createWithImageView:self frame:frame defaultImage:image propertiesBlock:^(UIImageView * _Nonnull imageView) {
            imageView.backgroundColor = [UIColor redColor];
        }];
    }
}

- (void)initWithDailyView {
    if (!_dailyView) {
        CGRect frame = CGRectMake(17.5, self.height - kAEPointsAcquireDailyViewHeight, self.width - 17.5 * 2, kAEPointsAcquireDailyViewHeight);
        _dailyView = [[AEPointsAcquireDailyView alloc] initWithFrame:frame];
        [self addSubview:_dailyView];
        @weakify(self);
        _dailyView.touchSignInBlock = ^{
            @strongify(self);
            if (self.touchSignInBlock) {
                self.touchSignInBlock();
            }
        };
    }
    
    [self.dailyView updateWithViewData:self.viewModel];
}

/// 点击签到
- (void)initWithBtnSignIn {
    if (!_btnSignIn) {
        NSString *title = [AEStringExten localizedValueWithKey:@"点击签到"];
        UIFont *font = [UIFont systemFontOfSize:12 weight:UIFontWeightBold];
        float width = [title widthForFont:font] + 2;
//        CGRect frame = CGRectMake(self.width - 56 - width, self.dailyView.top - 4, width, 30);
        CGRect frame = CGRectMake(self.width - 56 - width, self.dailyView.top - 0, width, 30);
        if (IPHONEX_TOP_SPACE > 0) {
            frame.origin.y = frame.origin.y - 4;
        }
        _btnSignIn = [UIButton createWithButton:self frame:frame font:font target:self action:@selector(actionWithSignIn:) propertiesBlock:^(UIButton * _Nonnull button) {
            [button setTitle:title forState:UIControlStateNormal];
            [button setTitleColor:[UIColor colorWithHexString:@"#F64903"] forState:UIControlStateNormal];
        }];
    }
}

- (void)actionWithSignIn:(id)sender {
    if (self.touchSignInBlock) {
        self.touchSignInBlock();
    }
}

- (void)updateWithViewData:(id)data {
    self.viewModel = data;
    [self initWithDailyView];
    
    [self initWithBtnSignIn];
}

@end
